import { Component, OnInit } from '@angular/core';
import { MessageGetDto } from './dto/messages.get.dto';
import { MessagesService } from './messages.service';

@Component({
  selector: 'app-messages',
  templateUrl: './messages.component.html',
  styleUrls: ['./messages.component.css']
})
export class MessagesComponent implements OnInit {
  messages: MessageGetDto[];

  constructor(private messagesService: MessagesService) {}

  ngOnInit() {
    this.fetchMessages();
  }

  fetchMessages() {
    this.messagesService.getMessages().subscribe(messagesGetDto => {
      this.messages = [...messagesGetDto.reverse()];
    });
  }
}
